import { getOrderStatus } from "@/api/modules/transactionManagement";
import { Space, Tag } from "antd";
import { keys, map, join, sumBy, isEmpty } from "lodash";
import styles from "./index.module.less";
import { getCategoryList, getModalityList } from "@/api/modules/course";
import { Link } from "react-router-dom";

export const COURSE_STATUS = {
	//下架
	down: -1,
	//上架
	up: 1,
	//待上架
	waitUp: 0
};

export const getSearchOptions = (info: string, { modalityList, categoryList }) => {
	return [
		{
			type: "input",
			placeholder: "课程关键字",
			name: "keyword"
		},
		{
			type: "input",
			placeholder: "ID",
			name: "course_id"
		},

		{
			type: "select",
			placeholder: "形式",
			name: "course_menus_id",
			// params: info ?? {},
			options: modalityList
		},
		{
			type: "select",
			placeholder: "类别",
			name: "base_course_category_id",
			// params: info ?? {},
			options: categoryList
		}
	];
};

export enum TAB_VALUES {
	//全部
	all = "",
	//已上架
	up = COURSE_STATUS.up,
	//待上架
	waitUp = COURSE_STATUS.waitUp
}

export const TABS = [
	{
		label: "全部",
		key: TAB_VALUES.all
	},
	{
		label: "已上架",
		key: TAB_VALUES.up
	},
	{
		label: "待上架",
		key: TAB_VALUES.waitUp
	}
];

export const getTableColumns = ({ modalityList, categoryList }) => [
	{
		title: "课程名称",
		dataIndex: "course_name",
		width: 200,
		align: "left",
		className: styles.shop,
		// ellipsis: true,
		render: (_, record) => {
			return <Link to={`/courseCreate?id=${record?.course_id}&isView=1`}>{record?.course_name}</Link>;
		}
	},
	{
		title: "ID",
		dataIndex: "course_id",
		width: 140,
		ellipsis: true
	},
	{
		title: "形式",
		dataIndex: "base_course_category_id",
		width: 140,
		renderText: v => {
			return modalityList?.find(i => i?.value == v)?.label ?? "-";
		}
	},
	{
		title: "类别",
		dataIndex: "course_menus_id",
		width: 140,
		renderText: v => {
			return categoryList?.find(i => i?.value == v)?.label ?? "-";
		}
	},
	{
		title: "授课人",
		dataIndex: "teacher",
		width: 140
	},
	{
		title: "介绍",
		dataIndex: "description",
		width: 200,
		ellipsis: true
	},
	{
		title: "播放量",
		dataIndex: "view_num",
		width: 140
	},
	{
		title: "创建时间",
		dataIndex: "created_at",
		width: 160,
		sorter: true
	},
	{
		title: "状态",
		dataIndex: "course_status",
		width: 160,
		render: (_, record) => {
			const value = record?.course_status;
			const bgColor = value === COURSE_STATUS.up ? "#E5FDE9" : "#FFF8ED";
			const color = value === COURSE_STATUS.up ? "#0B801E" : "#DE6700";
			// const bgColor =
			// 	value === PRODUCT_STATUS_VALUES.sales
			// 		? "#E5FDE9"
			// 		: value === PRODUCT_STATUS_VALUES.sale_pending
			// 		? "#FFF8ED"
			// 		: value === PRODUCT_STATUS_VALUES.off_shelf
			// 		? "#F3F4F7"
			// 		: "";
			// const color =
			// 	value === PRODUCT_STATUS_VALUES.sales
			// 		? "#0B801E"
			// 		: value === PRODUCT_STATUS_VALUES.sale_pending
			// 		? "#DE6700"
			// 		: value === PRODUCT_STATUS_VALUES.off_shelf
			// 		? "#7E7E7E"
			// 		: "";
			return (
				<Tag style={{ background: bgColor, color, border: "none", marginRight: 0 }}>
					{value === COURSE_STATUS.up
						? "运营中"
						: value === COURSE_STATUS.down
						? "已下架"
						: value === COURSE_STATUS.waitUp
						? "待上架"
						: "-"}
				</Tag>
			);
		}
	}
];
